<?php

/**
 * +---------------------------------------------------------------
 * | Author: 北京永青宇创科技有限公司
 * | Date: 2020/03/12
 * | 版本: 6.0
 * +---------------------------------------------------------------
 * | CopyRight: 北京永青宇创科技有限公司 All rights reserved.
 * +---------------------------------------------------------------
 * | 版权声明：云豹不是一个自由软件，是云豹官方推出的商业源码。
 * | 严禁在未经许可的情况下拷贝、复制、传播、使用云豹的任意代码
 * | 如有违反，请立即删除，否则您将面临承担相应，法律责任的风险。
 * | 如果需要取得官方授权，请联系官方 https://www.gepardshop.com
 * +---------------------------------------------------------------
 */

namespace app\mall\controller;

use app\common\controller\Ucenter;


class User extends Ucenter {
	protected $noNeedLogin = [];
	protected $noNeedRight = ['*'];

	protected function initialize()
	{
		parent::initialize();
		$this->app_id = 100001029;

		$this->getUser();

		$this->setItem();

		//config('site_name').
		$this->assign('site_name', config('site_name') . ' | 积分商城');
		$this->assign('meta_title', ' 积分商城');
	}

	private function setItem()
	{
		$order_count  = model('mall/mallOrder')->where(['user_id' => $this->auth->id])->count('id');
		$bookmark_count = model('mall/mallBookmark')->where(['user_id' => $this->auth->id,'status'=>1])->count('id');
		$history_count = model('mall/mallHistory')->where(['user_id' => $this->auth->id,'status'=>1])->count('id');

		$this->count_items = [
			['title' => '订单总数', 'value' => $order_count, 'url' => url('mall/my.order/index')],
			['title' => '浏览足迹', 'value' => $history_count, 'url' => url('mall/my.history/index')],
			['title' => '我的积分', 'value' => $this->user_info['score']],
		];
		$this->assign_sub_menu($this->app_id);
	}

    private function getUser()
    {

    }

    public function _quicker()
    {
        $order_list  = model('mall/mallOrder')->where(['user_id' => $this->auth->id])->order('create_time desc,id desc')->limit('8')->select();
        foreach ($order_list as &$item)
        {
            $goods_info = model('mall/MallGoods')->where(['id' => $item['goods_id']])->find();
            $item['category_name'] = $goods_info['category_name'];
            $item['description'] = $goods_info['description'];
        }
        $this->assign('order_list',$order_list);

        $history_list = model('mall/mallHistory')->where(['user_id' => $this->auth->id])->order('create_time desc,id desc')->limit('8')->select();
        foreach ($history_list as &$item)
        {
            $goods_info = model('mall/MallGoods')->where(['id' => $item['goods_id']])->find();
            $item['description'] = $goods_info['description'];
	        $item['title'] = $goods_info['title'];
	        $item['price'] = $goods_info['price'];
        }
        $this->assign('history_list',$history_list);
    }

	public function index()
	{
	    $this->_quicker();
		$order_count  = model('mall/mallOrder')->where(['user_id' => $this->auth->id])->count('id');
		$bookmark_count = model('mall/mallBookmark')->where(['user_id' => $this->auth->id,'status'=>1])->count('id');
		$history_count = model('mall/mallHistory')->where(['user_id' => $this->auth->id,'status'=>1])->count('id');
		$this->assign('order_count',$order_count);
		$this->assign('history_count',$history_count);
		return $this->fetch('user/index');
	}

}